package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsProductCommentLabel;
import com.macro.mall.model.PmsProductCommentLabelRes;
import com.macro.mall.service.PmsProductCommentLabelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品评论标签管理
 */
@Controller
@Tag(name = "PmsProductCommentLabelController", description = "商品评论标签管理")
@RequestMapping("/productAttribute")
public class PmsProductCommentLabelController {
    @Resource
    public PmsProductCommentLabelService commentLabelService;
    @Operation(summary = "获取全部标签列表")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsProductCommentLabel>> getList() {
        List<PmsProductCommentLabel> list=commentLabelService.listAll();
        return CommonResult.success(list);
    }
    @Operation(summary = "添加签列表")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addPmeProductCommentLabel(@RequestBody PmsProductCommentLabel pmsProductCommentLabel) {
        commentLabelService.addPmeProductCommentLabel(pmsProductCommentLabel);
        return CommonResult.success("添加成功");
    }
    @Operation(summary = "修改签列表")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updatePmeProductCommentLabel(@RequestBody PmsProductCommentLabel pmsProductCommentLabel) {
        commentLabelService.updatePmeProductCommentLabel(pmsProductCommentLabel);
        return CommonResult.success("修改成功");
    }
    @Operation(summary = "删除签列表")
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delPmeProductCommentLabel(@PathVariable Integer id) {
        commentLabelService.delPmeProductCommentLabel(id);
        return CommonResult.success("删除成功");
    }
    @Operation(summary = "回显签列表")
    @RequestMapping(value = "/find/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<PmsProductCommentLabel> findPmeProductCommentLabel(@PathVariable Integer id) {
        PmsProductCommentLabel productCommentLabel=commentLabelService.findPmeProductCommentLabel(id);
        return CommonResult.success(productCommentLabel);
    }
    @Operation(summary = "根据类型查找标签列表")
    @RequestMapping(value = "/findByTypeId/{cid}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<PmsProductCommentLabel>> findByTypeId(@PathVariable Integer cid) {
        PmsProductCommentLabelRes pmsProductCommentLabelRes = new PmsProductCommentLabelRes();
        pmsProductCommentLabelRes.setCid(cid);
        List<PmsProductCommentLabel> list=commentLabelService.findByTypeId(pmsProductCommentLabelRes);
        return CommonResult.success(CommonPage.restPage(list));
    }
}
